package com.gztms.usermgnt.handler.exception;

import com.gztms.enums.AppCodeEnum;
import com.gztms.exception.SystemException;
import com.gztms.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Zoey
 * @date 2023/5/2 0:31
 * @Description TODO
 **/
@ControllerAdvice
@Slf4j
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public ResultUtil systemExceptionHandler(SystemException e) {
        // 打印异常信息
        log.error("系统异常！ {}",e);
        return ResultUtil.errorResult(e.getCode(), e.getMsg());
    }

//    @ExceptionHandler(Exception.class)
//    public ResultUtil systemExceptionHandler(Exception e) {
//        // 打印异常信息
//        log.error("系统异常！ {}",e);
//        return ResultUtil.errorResult(AppCodeEnum.SYSTEM_ERROR.getCode(), e.getMessage());
//    }

}
